package com.wuhunyu.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuhunyu.commonutils.check.Check;
import com.wuhunyu.servicebase.exception.Assert;
import java.util.HashMap;
import java.util.Map;

/**
 * 封装page对象
 *
 * @author wuhunyu
 * @version 1.0
 * @date 2021-01-24 16:07
 */
public class PageUtil<T> {

    public Map<String, Object> generateMap(Page<T> page) {
        // 参数校验
        Assert.isRight(Check.isBlank(page), "page参数不能为空");
        // 封装结果集
        Map<String, Object> map = new HashMap<>(16);
        map.put("current", page.getCurrent());
        map.put("total", page.getTotal());
        map.put("pages", page.getPages());
        map.put("size", page.getSize());
        map.put("hasPrevious", page.hasPrevious());
        map.put("hasNext", page.hasNext());
        map.put("items", page.getRecords());
        return map;
    }

}
